<%layout("/common/_layout.html"){ %>
<script type="text/javascript">

function changeStatus(url,id,targetStatus) {
    
    $.ajax({
        url : url,
        data : {"id":id,"target_status":targetStatus},
        dataType : "json",
        async : true,
        success : function(data) {
            //parent.swal({title: "配置成功!", text: data.message, type: "success",timer: 2000,   showConfirmButton: false});
            parent.layer.msg("配置: " + data.message);
        }
        
    });
    
}
 
$(function(){
    var $mycheckbox = $('.switch-button').find("input[type='checkbox']");
    $mycheckbox.each(function(){
        var myid = $(this).attr("id");
        $("#"+myid).on({
            'switchChange.bootstrapSwitch': function(event, state) {
              var id =$(this).attr("id") ;
              console.log("switch:"+id+":"+state);
              changeStatus("${base}/product/changeStatus",id,state?1:0);
            }
        });
    });

  });
  
 
</script>



  <%#ajax userTable:{%>
  <div class="am-cf am-padding">
    <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">商品管理</strong> / <small>商品管理</small></div>
  </div>
  
  <div class="am-g">
    <%include("product_query.tpl"){}%>
 
    <div class="am-u-sm-12 am-u-md-12" style="padding:0 1.6rem 1.6rem 1rem;margin:0;">
       <div class="am-btn-toolbar" style="padding-left:.5rem;">
         <div class="am-btn-group am-btn-group-xs">
           <%if(so.hasPermission("PRODUCT_ADD")) {%>
            <div class="am-btn-group am-btn-group-xs am-form-file"><button type="button" id="bt_add" class="am-btn"  onclick="location.href='${base}/product/add'"><span class="am-icon-plus"> 新增</span></button></div>
           <%}%>
           <%if(so.hasPermission("PRODUCT_ENABLE")) {%>
            <button type="button" id="enableButton" disabled="disabled" class="am-btn am-btn-default"  onclick="enableAll('${base}/product/enable')"><span class="am-icon-toggle-on"></span> 启用</button>
           <%}%>
           <%if(so.hasPermission("PRODUCT_DISABLE")) {%>
            <button type="button" id="disableButton" disabled="disabled" class="am-btn am-btn-default"  onclick="disableAll('${base}/product/disable')"><span class="am-icon-toggle-off"></span> 禁用</button>
           <%}%>
           
           <!--
           <%if(so.hasPermission("PRODUCT_DELETE")) {%>
            <button type="button" id="deleteButton" disabled="disabled" class="am-btn am-btn-default"  onclick="deleteAll('${base}/product/delete')"><span class="am-icon-trash-o"></span> 删除</button>
           <%}%>
           -->
         </div>
       </div>
    </div>

   <div class="am-g">
     <div class="am-u-sm-12">
        <div class="am-scrollable-horizontal">
         <table class="am-table am-table-striped am-table-hover table-main" >
             <thead>
                  <tr class="am-text-nowrap">
                     <th class="table-check">
                     <input type="checkbox"  id="allCheck"/></th>
                     <th class="table-title" style="width:36%">名称</th>
                     <th class="table-title" style="width:16%">所属品牌</th>
                     <!-- <th class="table-title">所属分类</th> -->
                     <!-- <th class="table-title">已售</th> -->
                     <!-- <th class="table-title">库存</th> -->
                     <th class="table-title">所属机构</th>
                     <th class="table-title">创建人</th>
                     <th class="table-title">上架时间</th>
                     <th class="table-title">下架时间</th>
                     <th class="table-title">是否启用</th>
                     <th class="table-title">排序</th>
                     <th class="table-title">操作</th>
                      <th class="table-title">最后操作时间</th>
                  </tr>
             </thead>
          <tbody>
             <%for(item in pager.list!){%>
                <tr>
                 <td><input type="checkbox" name="ids" value="${item.id}"></td>
                 <td>${item.name}</td>
                 <td>${item.brand_name}</td>
                 <!-- <td>${item.category_name}</td> -->
                 <!-- <td>${item.sold!"0"}</td> -->
                 <!-- <td>${item.stock!"0"}</td> -->
                 <td>${item.orgName}</td>
                 <td>${item.real_name}</td>
                 <td>${item.put_on_time,dateFormat="yyyy-MM-dd HH:mm:ss"}</td>
                 <td>${item.put_off_time,dateFormat="yyyy-MM-dd HH:mm:ss"}</td>
                 <td id='enabled'>${item.isEnabled}</td>
                 <td>${item.sort}</td>
                 <!-- <td>
                    <div class="switch-button"> 
                        <input id="${item.id}"  type="checkbox" data-size='xs' data-am-switch  data-off-text="已下架" data-on-text="已上架"  
                        <%if(item.status==1){%>
                                checked
                        <%}else{%><%}%>
                        />
                    </div>
                 </td> -->
                 
                         
                 
                 <td id='operated'>
                    <div class="am-btn-toolbar">
                        <div class="am-btn-group am-btn-group-xs">
                        
                        
                            <%if(so.hasPermission("PRODUCT_EDIT")){%>
                            <div id ="edit-div" class="am-btn-toolbar <%if(item.enabled == 1) {%>
                            am-hide
                            <%}%>
                            ">
                            
                            
                                <button type="button" class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="location.href='${base}/product/edit?id=${item.id}'">
                                    <span class="am-icon-pencil-square-o"></span>编辑</button>
                           
                            </div>
                            <%}%>
                             
                            
                            <%if(so.hasPermission("PRODUCT_PREVIEW")) {%>
                                <button type="button" class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="location.href='${base}/product/preview?id=${item.id}'">
                                    <span class="am-icon-pencil-square-o"></span>预览</button>
                            <%}%>
                        </div>
                    </div>
                 </td>
                    <td>${item.operated_time,dateFormat="yyyy-MM-dd HH:mm:ss"}</td>
                </tr>
             <%}%> 
          </tbody>
       </table>
       </div>
       
       <div class="am-cf">
         <!-- 分页 -->
         <%if (pager.list.~size > 0){%>
             <div class="am-fr">
                 <% include("/admin/common_pager.tpl"){}%>
             </div>
         <%}else{%>
             <div class="am-kai">
               <h3>没有找到任何记录!</h3>
             </div>
         <%}%>
      </div>
  
      </div>
  </div>

   
 <div class="am-modal am-modal-no-btn" tabindex="-1" id="modal">
    <div class="am-modal-dialog">
      <div class="am-modal-hd">
        <i class="am-icon-refresh am-icon-spin"></i>
        <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
      </div>
      <div class="am-modal-bd">
        正在处理，请稍等...
      </div>
    </div>
  </div>
<%}%>
<%}%> 



